package com.amado.course10Function;

import java.util.Scanner;

public class CoachStudentSystem {
	// 教练员与学员关联关系
	static String[][] coachStudentMapping = new String[10][4];
	// 评价
	static String[][] comments = new String[10][2];
	// 教练员
	static String[][] coachs = new String[10][5];
	static String[][] students = new String[10][6];
	static int coachsCount, commentsCount, studentsCount, coachStudentMappingCount;
	static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {
		// 初始化
		init();
		// 打印
		showMenu();
	}

	/**
	 * 初始化数据
	 */
	public static void init() {
		coachs[coachsCount++] = new String[] { "JLY001", "李小刚", "男", "38", "科目二" };
		coachs[coachsCount++] = new String[] { "JLY002", "周春芳", "女", "40", "科目二" };
		coachs[coachsCount++] = new String[] { "JYL003", "周春芳", "女", "28", "科目三" };
		coachs[coachsCount++] = new String[] { "JYL004", "王五", "男", "28", "科目三" };
		coachs[coachsCount++] = new String[] { "JYL005", "张小花", "女", "28", "科目一" };

		students[studentsCount++] = new String[] { "XY001", "张三", "男", "28", "13820440033", "123456" };
		students[studentsCount++] = new String[] { "XY001", "张三", "男", "28", "13820440033", "123456" };
		students[studentsCount++] = new String[] { "XY002", "张三", "男", "20", "14200443322", "Abc123" };

		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JLY001", "XY001" };
		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JLY001", "XY002" };
		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JYL005", "XY001" };
		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JYL005", "XY002" };
		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JYL003", "XY002" };
		coachStudentMapping[coachStudentMappingCount++] = new String[] { "JYL004", "XY001" };

		comments[commentsCount++] = new String[] { "JLY001", "非常好", "XY001", "1" };
		comments[commentsCount++] = new String[] { "JLY001", "不好", "XY002", "2" };
		comments[commentsCount++] = new String[] { "JYL005", "X.、、、、、、", "XY002	4" };
		comments[commentsCount++] = new String[] { "JYL003", "在 。。。。。。", "XY002", "5" };
	}

	public static void showMenu() {
		int loginFlag = 0;
		while (true) {
			System.out.println("请输入账号");
			String userName = scanner.next();
			System.out.println("请输入密码");
			String password = scanner.next();
			loginFlag = login(userName, password);
			if (loginFlag >= -1) {
				break;
			}
			System.out.println("用户名密码错误，请重新登陆");
		}
		//管理员登陆
		if (loginFlag == -1) {
			showAdminMenu();
			//学员登陆
		} else if (loginFlag >= 0) {
			showStudentMenu(loginFlag);
		}
	}

	public static void showAdminMenu() {
		System.out.println("1、添加教练员，2添加学员、3绑定学员与教练员");
		int menuSelect = scanner.nextInt();
		if (menuSelect == 1) {
			
		}else if (menuSelect == 2) {
			
		}else if (menuSelect == 3) {
			
		}
	}

	public static void showStudentMenu(int studentIndex) {
		while (true) {
			System.out.println("1、修改密码2、查看自己的教练员信息3评价自己的教练员");
			int menuSelect = scanner.nextInt();
			if (menuSelect == 1) {
				
			}else if (menuSelect == 2) {
				//ctrl +鼠标左键
				printCoachs(students[studentIndex][0]);
			}else if (menuSelect == 3) {
				
			}
		}
	}

	/**
	 * 登陆
	 * 
	 * @param userName 用户名
	 * @param password 密码
	 * @return 管理员登陆成功返回-1，普通用户登陆成功返回下标>=0,登陆失败返回-2
	 */
	public static int login(String userName, String password) {
		if ("admin".equals(userName) && "admin".equals(password)) {
			return -1;
		} else {
			for (int i = 0; i < studentsCount; i++) {
				if (userName.equals(students[i][0]) && password.equals(students[i][5])) {
					return i;
				}
			}
		}
		return -2;
	}

	/**
	 * 打印学员编号对应的教练员信息
	 * 
	 * @param studentNum 学员编号
	 */
	public static void printCoachs(String studentNum) {
		System.out.println("科目\t教练员\t评价星级\t评价内容");
		// 打印学员与教练员的对应关系
		for (int i = 0; i < coachStudentMappingCount; i++) {
			if (coachStudentMapping[i][1].equals(studentNum)) {
				String[] coach = getCoachInfo(coachStudentMapping[i][0]);
				String[] commentInfo = getCommentInfo(coachStudentMapping[i][0], coachStudentMapping[i][1]);
				// 如果 commentInfo != null 条件为true取 commentInfo[3] 否则取""
				String start = commentInfo != null ? commentInfo[3] : "";
				String comment = commentInfo != null ? commentInfo[1] : "";
				System.out.println(coach[4] + "\t" + coach[1] + "\t" + start + "\t" + comment);
			}
		}
	}

	/**
	 * 根据教练员编号获取教练员信息
	 * 
	 * @param coachNum
	 * @return
	 */
	public static String[] getCoachInfo(String coachNum) {
		for (String[] coach : coachs) {
			// 根据学员过虑教练员信息
			if (coachNum.equals(coach[0])) {
				// 教练员编码
				return coach;
			}
		}
		return null;
	}

	/**
	 * 根据学员与教练员编号获取评价
	 * 
	 * @param coachNum
	 * @param studentNum
	 * @return
	 */
	public static String[] getCommentInfo(String coachNum, String studentNum) {
		for (String[] comment : comments) {
			// 根据学员、教练员过滤
			if (coachNum.equals(comment[0]) && studentNum.equals(comment[2])) {
				return comment;
			}
		}
		return null;
	}
}
